﻿package mortal.game.view.copy.crossMainCity.panels
{
    import Message.Public.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import mortal.common.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.crossMainCity.panels.sub.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.interfaces.*;

    public class MainCityRankPanel extends BaseWindow
    {
        private var _winBg:ScaleBitmap;
        private var _tab:GTabarNew;
        private var _bg:MainCityRankTotalBg;
        private var _list:MainCityRankList;
        private var _tabData:Array;
        public static const Index_Total:int = 0;
        public static const Index_MyGuild:int = 1;
        public static const Index_EnemysGuild:int = 2;

        public function MainCityRankPanel(param1:ILayer = null)
        {
            this._tabData = [{name:0, label:Language.getString(20958)}, {name:1, label:Language.getString(20959)}, {name:2, label:Language.getString(20960)}];
            super(param1);
            setSize(800, 542);
            if (CopyUtil.isInMainCityBattleFinalCopy || Cache.instance.mainCity.isFinalBattleDuration)
            {
                this.title = Language.getString(20961);
            }
            else
            {
                this.title = Language.getString(20962);
            }
            return;
        }// end function

        public function changeToTabIndex(param1:int) : void
        {
            this._tab.selectedIndex = param1;
            this.onTabBarChange(null);
            return;
        }// end function

        public function updateRankDatas(param1:Array) : void
        {
            if (Cache.instance.mainCity.lastInFinal)
            {
                this._list.setScoreDesc(Language.getString(20963));
            }
            else
            {
                this._list.setScoreDesc(Language.getString(20964));
            }
            this._list.datas = param1;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._winBg = UIFactory.bg(9, 61, 788, 433, this);
            this._tab = UIFactory.gTabBarNew(0, 32, this._tabData, 800, 542, 62, 26, this, this.onTabBarChange, "TabButtonNew");
            this._bg = UICompomentPool.getUICompoment(MainCityRankTotalBg) as MainCityRankTotalBg;
            this._bg.x = 11;
            this._bg.y = 64;
            this.addChild(this._bg);
            this._list = UICompomentPool.getUICompoment(MainCityRankList) as MainCityRankList;
            this._list.x = this._bg.x;
            this._list.y = this._bg.y + this._bg.height + 1;
            this.addChild(this._list);
            this._list.pageNum = 10;
            return;
        }// end function

        private function onTabBarChange(param1) : void
        {
            var _loc_2:SEntityId = null;
            var _loc_3:Boolean = false;
            var _loc_4:Boolean = false;
            var _loc_5:Array = null;
            switch(this._tab.selectedIndex)
            {
                case MainCityRankPanel.Index_Total:
                {
                    _loc_2 = Cache.instance.mainCity.winGuildID;
                    if (_loc_2 != null)
                    {
                        this.addChild(this._bg);
                        this._list.y = this._bg.y + this._bg.height + 1;
                        this._list.pageNum = 10;
                        this.updateRankDatas(Cache.instance.mainCity.finalPlayersTotal);
                        _loc_3 = Cache.instance.guild.isMyGuild(_loc_2);
                        _loc_4 = Cache.instance.mainCity.isKOBattleDuration;
                        _loc_5 = [];
                        this._bg.updateDatas(_loc_4, _loc_3, Cache.instance.guild.selfGuildInfo.baseInfo.guildName, Cache.instance.mainCity.getMyGuildScore(), Cache.instance.mainCity.getMyScore(), Cache.instance.mainCity.getMyGuildRewards(_loc_4, _loc_3));
                    }
                    else
                    {
                        this._list.y = this._bg.y;
                        this._list.pageNum = 12;
                        DisplayUtil.removeMe(this._bg);
                        this.updateRankDatas(Cache.instance.mainCity.finalPlayersTotal);
                    }
                    break;
                }
                case MainCityRankPanel.Index_MyGuild:
                {
                    this._list.y = this._bg.y;
                    this._list.pageNum = 12;
                    DisplayUtil.removeMe(this._bg);
                    this.updateRankDatas(Cache.instance.mainCity.finalPlayersSelf);
                    break;
                }
                case MainCityRankPanel.Index_EnemysGuild:
                {
                    this._list.y = this._bg.y;
                    this._list.pageNum = 12;
                    DisplayUtil.removeMe(this._bg);
                    this.updateRankDatas(Cache.instance.mainCity.finalPlayersEnemy);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._winBg.dispose(param1);
            this._winBg = null;
            this._tab.dispose(param1);
            this._tab = null;
            this._bg.dispose(param1);
            this._bg = null;
            this._list.dispose(param1);
            this._list = null;
            return;
        }// end function

    }
}
